/**
 * Created by DukeCrushIt on 2015/8/24.
 */
class PropItemRender extends eui.ItemRenderer {
    public constructor() {
        super();
        this.skinName = "pet.PropItemRenderSkin";
        this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onUse, this);
        this.name = "prop"+this.hashCode;
    }

    private onUse(evt:egret.TouchEvent) {
        SoundMgr.getInstance().playEffect(SoundMgr.BTN);
        var goodInfo:GoodInfo = Model.GetGoodInfoById(this.data.propId);
        if( goodInfo.hidden){
            ShowHint(goodInfo.descs);
            return;
        }
        if( PetMgr.getInstance().curPet.type == Model.GOOD_TYPE_DOG){
            if( goodInfo.use4Dog){
                window["__use"](this.data.propId, PetMgr.getInstance().curPet.petId);
                AnimationController.getInstance().wakeUp("mypet");
            }else{
                ShowHint("这是喵喵的专属道具");
            }
        }else{
            if( goodInfo.use4Cat){
                window["__use"](this.data.propId, PetMgr.getInstance().curPet.petId);
                AnimationController.getInstance().wakeUp("mypet");
            }else{
                ShowHint("这是汪汪的专属道具");
            }
        }
    }
    private propCount:number=-1;
    public dataChanged() {
        super.dataChanged();
        this.icon.source = GameConst.Res_Root + "resource/assets/items/" + this.data.propId + ".png";
        if( this.propCount != this.data.count){
            this.group_count.text = "x"+this.data.count;
            //GetUIAssetsNum(this.data.count,this.group_count,1.0,true);
            this.propCount = this.data.count
        }
    }

    public icon:eui.Image;
    public group_count:eui.BitmapLabel;
    public partAdded(name:string, instance:any) {
        super.partAdded(name, instance);
        if (name == "icon") {
            this.icon = instance;
        }else if (name == "group_count") {
            this.group_count = instance;
            this.group_count.textAlign = "right";
        }
    }
}